package com.itheima.controller;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 学员列表查询
     */
    @GetMapping
    public Result pageStudent(String name, Integer degree, Integer clazzId,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer pageSize){

        PageBean<Student> studentData = studentService.getStudent(name,degree,clazzId,page,pageSize);
        return Result.success(studentData);
    }

    /**
     * 新增学生信息
     */
    @PostMapping
    public Result addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        return Result.success();
    }

    /**
     * 根据ID查询学生
     */
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable("id") Integer id){
        Student studentDate = studentService.getStudentById(id);
        return Result.success(studentDate);
    }

    /**
     * 修改学员
     */
    @PutMapping
    public Result putStudent(@RequestBody Student student){
        studentService.putStudent(student);
        return Result.success();
    }

    /**
     * 删除学生信息
     */
    @DeleteMapping("/{ids}")
    public Result deleteStu(@PathVariable("ids") List<Integer> ids){
        log.info("ids={}",ids);
        studentService.deleteStu(ids);
        return Result.success();
    }

    /**
     * 违纪处理
     */
    @PutMapping("/violation/{id}/{score}")
    public Result violationStu(@PathVariable("id") Integer id,@PathVariable("score") Integer score){
        //log.info("id={},score={}",id,score);
        studentService.violationStu(id,score);
        return Result.success();
    }
}

